from django.db import models
from datetime import datetime


# Create your models here.
# 所有广告的备份表model
class Advertisement(models.Model):
    id = models.AutoField(verbose_name='id', primary_key=True)
    url = models.TextField(verbose_name='链接', blank=False, default='')
    title = models.TextField(verbose_name='标题', blank=False, default='')
    img = models.TextField(verbose_name='图片信息', blank=False, default='')
    read_count = models.CharField(max_length=80, verbose_name='浏览次数', default='暂无')
    share_count = models.CharField(max_length=80, verbose_name='分享次数', default='暂无')
    discover_count = models.IntegerField(verbose_name='发现次数')
    source = models.CharField(max_length=80, verbose_name='广告主', default='暂无')
    industry = models.CharField(max_length=30, verbose_name='行业', default='暂无')
    public_time = models.DateTimeField(verbose_name='发布时间', null=True, max_length=0)
    create_time = models.DateTimeField(verbose_name='发现时间', null=True, max_length=0)
    update_time = models.DateTimeField(verbose_name='更新时间', null=True, max_length=0)
    put_type = models.CharField(max_length=30, verbose_name='投放类型', default='图文')
    put_goal = models.CharField(max_length=30, verbose_name='投放目标', default='暂无')
    like_count = models.CharField(max_length=30, verbose_name='点赞次数', default='暂无')
    app_from = models.CharField(max_length=30, verbose_name='数据来源', default='暂无')
    model_from = models.CharField(max_length=30, verbose_name='模板来源', default='暂无')
    logo = models.CharField(max_length=80, verbose_name='logo', default='暂无')
    put_day_count = models.IntegerField(verbose_name='投放天数', default=0)
    discover_day_time = models.IntegerField(verbose_name='爬取天数', default=1)
    random_id = models.IntegerField(verbose_name='随机顺序', default=0)
    local_img = models.CharField(max_length=100, verbose_name='本地图片路径', default='暂无')
    app_name = models.CharField(max_length=30, verbose_name='平台名称', default='暂无')
    app_id = models.IntegerField(verbose_name='平台id',default=0)
    image_feature = models.BinaryField(max_length=512,null=True) #特征码以二进制方式保存
    image_tag_1 = models.CharField(max_length=100, verbose_name='图片标签1', default='暂无')
    image_tag_2 = models.CharField(max_length=100, verbose_name='图片标签2', default='暂无')
    image_tag_3 = models.CharField(max_length=100, verbose_name='图片标签3', default='暂无')
    image_tag_4 = models.CharField(max_length=100, verbose_name='图片标签4', default='暂无')
    image_tag_5 = models.CharField(max_length=100, verbose_name='图片标签5', default='暂无')
    image_tag_6 = models.CharField(max_length=100, verbose_name='图片标签6', default='暂无')
    image_tag_7 = models.CharField(max_length=100, verbose_name='图片标签7', default='暂无')
    image_tag_8 = models.CharField(max_length=100, verbose_name='图片标签8', default='暂无')
    image_tag_9 = models.CharField(max_length=100, verbose_name='图片标签9', default='暂无')
    image_tag_10 = models.CharField(max_length=100, verbose_name='图片标签10', default='暂无')
    image_size = models.CharField(max_length=20, verbose_name='图片尺寸', default='')


    class Meta:
        verbose_name = '广告数据中间表'
        verbose_name_plural = verbose_name

    def __str__(self):
        return str(self.id)


# 随机数据model，用于详情页图表的随机数据
class RandomData(models.Model):
    id = models.AutoField(verbose_name='id', primary_key=True)
    industry_random_data = models.CharField(max_length=50, verbose_name='随机数', default='')
    zone_random_data = models.CharField(max_length=50, verbose_name='随机数', default='')
    age_random_data = models.CharField(max_length=50, verbose_name='随机数', default='')
    create_time = models.DateTimeField(verbose_name='创建时间', default=datetime.now)

    class Meta:
        verbose_name = '每日随机数表'
        verbose_name_plural = verbose_name

    def __str__(self):
        return str(self.id)


class TestBinaryField(models.Model):
    id = models.AutoField(verbose_name='id', primary_key=True)
    imageblob = models.BinaryField(max_length=512,default='')

    class Meta:
        verbose_name = 'test'
        verbose_name_plural = verbose_name

    def __str__(self):
        return str(self.id)
